#ifndef INTERFACE_H
#define INTERFACE_H

#include <stdint.h>
#include "sound.h"
typedef struct Game Game;

#define TRUE 1
#define FALSE 0

#define SPRITE_ACTIVE (uint8_t) 1
#define SPRITE_FLIP_X (uint8_t) 2
#define SPRITE_FLIP_Y (uint8_t) 4
#define MAX_SPRITES 8

#define TILE_WIDTH 28
#define TILE_HEIGHT 36

#define INPUT_RIGHT 1
#define INPUT_UP 2
#define INPUT_LEFT 4
#define INPUT_DOWN 8
#define INPUT_START 16
#define INPUT_P1_COIN 32
#define INPUT_P2_COIN 64
#define INPUT_DEBUG 128

typedef struct Sprite {
    uint8_t flags;
    int location_x;
    int location_y;

    uint8_t sprite;
    uint8_t palette;
} Sprite;

typedef struct Color {
    uint8_t r;
    uint8_t g;
    uint8_t b;
} Color;

typedef struct Palette {
    uint8_t colors[4];
} Palette;

typedef struct DisplayInfo {
    int screen_width;
    int screen_height;
    
    Color colors[32];
    const Palette* palettes;
    const uint8_t* characterGraphics;
    const uint8_t* spriteGraphics;

    uint8_t tiles[TILE_WIDTH][TILE_HEIGHT];
    uint8_t tile_palettes[TILE_WIDTH][TILE_HEIGHT];
    Sprite sprites[MAX_SPRITES];
} DisplayInfo;

typedef struct GameInterface {
    DisplayInfo display_info;
    uint8_t inputs;
    uint8_t last_inputs;

    Game* game;

    SoundManager sound;
} GameInterface;

extern void pacman_interface_init(GameInterface* interface);
extern void pacman_interface_destroy(GameInterface* interface);
extern void pacman_interface_update(GameInterface* interface);
extern void pacman_interface_setup_sound(GameInterface* interface, unsigned int sample_rate, SubmitAudioCallback callback, void* userdata);

extern DisplayInfo* pacman_interface_get_display_info(GameInterface* interface);
extern void pacman_interface_set_inputs(GameInterface* interface, uint8_t input_flags);

#endif